/*
 *reference for clock
 **/

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.Calendar;

public class TextClock1 extends JFrame{

    private JTextField _timeField;

    public TextClock1() {

        _timeField = new JTextField(5);

        _timeField.setEditable(false);

        _timeField.setFont(new Font("sansserif", Font.PLAIN, 48));

        JPanel content = new JPanel();

        content.setLayout(new FlowLayout());

        content.add(_timeField);

        this.setContentPane(content);

        this.setTitle("Text Clock 1");

        this.pack();

        this.setLocationRelativeTo(null);

        this.setResizable(false);

        javax.swing.Timer t = new javax.swing.Timer(1000, new ClockListener());

        t.start();

    }

    class ClockListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {

            Calendar now = Calendar.getInstance();

            int h = now.get(Calendar.HOUR_OF_DAY);

            int m = now.get(Calendar.MINUTE);

            int s = now.get(Calendar.SECOND);

            _timeField.setText("" + h + ":" + m + ":" + s);

        }

    }

    public static void main(String[] args) {

        JFrame clock = new TextClock1();

        clock.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        clock.setVisible(true);

    }

}
